package cn.huihuo.weibo.controller;

import cn.huihuo.weibo.bean.hot.HotResultBean;
import cn.huihuo.weibo.service.HotService;
import cn.huihuo.weibo.service.MessageService;
import cn.huihuo.weibo.service.ParticipationService;
import cn.jfinalbbs.common.BaseController;
import cn.jfinalbbs.common.Constants;
import cn.jfinalbbs.user.User;

/**
 * Created by zhengjunbo on 2015/10/30.
 */
public class HotController extends BaseController {
    public void index(){
        User user = getSessionAttr(Constants.USER_SESSION);

        setAttr("messageSize", user==null?"": MessageService.service.total(user.getStr("id")));

        setAttr("participationSize", user==null?"": ParticipationService.service.findTotalParticipation(user.getStr("id")));
        render("huihuo/hot.html");
    }

    public void findHot(){
        Integer pageStep = getParaToInt("pageStep");
        Integer count = getParaToInt("count");


        try {
            HotResultBean whatsHot = HotService.service.findWhatsHot(pageStep, count);
            success(whatsHot);
        } catch (Exception e) {
            e.printStackTrace();
            error("获取数据异常！");
        }
    }
}
